package io.renren.modules.category.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.renren.common.service.impl.CrudServiceImpl;
import io.renren.common.utils.ConvertUtils;
import io.renren.modules.category.dao.TInitialDao;
import io.renren.modules.category.dto.TInitialDTO;
import io.renren.modules.category.entity.TInitialEntity;
import io.renren.modules.category.service.TInitialService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 字母A-Z 及热门品牌分类
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2023-08-09
 */
@Service
public class TInitialServiceImpl extends CrudServiceImpl<TInitialDao, TInitialEntity, TInitialDTO> implements TInitialService {

    @Override
    public QueryWrapper<TInitialEntity> getWrapper(Map<String, Object> params){
        Long consumerId = (Long)params.get("consumerId");
        String code = (String) params.get("code");
        QueryWrapper<TInitialEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(consumerId), "consumer_id", consumerId);
        wrapper.eq(Objects.nonNull(code), "code", code);
        wrapper.orderByAsc("sort");
        return wrapper;
    }


    @Override
    public List<TInitialEntity> selectList(Map<String, Object> params){
        List<TInitialEntity> entityList = baseDao.selectList(getWrapper(params));
        return ConvertUtils.sourceToTarget(entityList, TInitialEntity .class);
    }


    public QueryWrapper<TInitialEntity> getWrapperCode(Map<String, Object> params){
        String code = (String) params.get("code");
        QueryWrapper<TInitialEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(Objects.nonNull(code), "code", code);
        wrapper.orderByAsc("sort");
        return wrapper;
    }

    @Override
    public List<TInitialEntity> selectListByCode(Map<String, Object> params){
        List<TInitialEntity> entityList = baseDao.selectList( getWrapperCode(params));
        return ConvertUtils.sourceToTarget(entityList, TInitialEntity .class);
    }

    

}